<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>屏蔽规则</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <style>
    .area .layui-form-item {
      clear: none !important;
    }
    .area .layui-form-label{
      margin-left: -16px;
    }
  </style>
</head>
<body>


<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">


  <div class="layui-form-item">
    <label class="layui-form-label"><i class="layui-icon layui-icon-about" style="font-size: 14px;" lay-tips="屏蔽后只展示C级书">启用开关</i></label>
    <div class="layui-input-block">
      <input name="id" type="hidden" value="{$id}">
      <input type="checkbox" name="switch" value="1" lay-skin="switch" lay-text="开启|关闭" {if $info.switch == 1}checked{/if}>
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">链接替换书</label>
    <div class="layui-input-inline">
      <input type="number" name="link_replace_nid" value="{$info.link_replace_nid}" placeholder="请输入小说ID" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">屏蔽区域</label>
    <div class="layui-input-block area">
      <div id="regionTest"></div>
      <input type="hidden" value="{$info.area}" id="area" name="area">
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label"><i class="layui-icon layui-icon-about" style="font-size: 14px;" lay-tips="开发时间段对IP库无效">屏蔽IP库</i></label>
    <div class="layui-input-block">
      {foreach $ipL as $vo}
      <input type="checkbox" name="iplib_ids[]" value="{$vo.id}" title="{$vo.title}" lay-skin="primary" {in name="$vo.id" value="$info.libIds"}checked{/in}>
      {/foreach}
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">白名单用户</label>
    <div class="layui-input-block">
        <textarea name="white_uids" placeholder="多个用户id用半角逗号隔开" class="layui-textarea" lay-verify="uids" >{$info.white_uids}</textarea>
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">开放时间段</label>
    <div class="layui-input-block">
      <input type="checkbox" name="open_hour[]" title="00" value="00" lay-skin="primary" {if $info && in_array('00',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="01" value="01" lay-skin="primary" {if $info && in_array('01',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="02" value="02" lay-skin="primary" {if $info && in_array('02',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="03" value="03" lay-skin="primary" {if $info && in_array('03',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="04" value="04" lay-skin="primary" {if $info && in_array('04',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="05" value="05" lay-skin="primary" {if $info && in_array('05',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="06" value="06" lay-skin="primary" {if $info && in_array('06',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="07" value="07" lay-skin="primary" {if $info && in_array('07',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="08" value="08" lay-skin="primary" {if $info && in_array('08',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="09" value="09" lay-skin="primary" {if $info && in_array('09',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="10" value="10" lay-skin="primary" {if $info && in_array('10',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="11" value="11" lay-skin="primary" {if $info && in_array('11',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="12" value="12" lay-skin="primary" {if $info && in_array('12',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="13" value="13" lay-skin="primary" {if $info && in_array('13',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="14" value="14" lay-skin="primary" {if $info && in_array('14',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="15" value="15" lay-skin="primary" {if $info && in_array('15',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="16" value="16" lay-skin="primary" {if $info && in_array('16',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="17" value="17" lay-skin="primary" {if $info && in_array('17',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="18" value="18" lay-skin="primary" {if $info && in_array('18',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="19" value="19" lay-skin="primary" {if $info && in_array('19',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="20" value="20" lay-skin="primary" {if $info && in_array('20',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="21" value="21" lay-skin="primary" {if $info && in_array('21',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="22" value="22" lay-skin="primary" {if $info && in_array('22',$info.hours)}checked{/if}>
      <input type="checkbox" name="open_hour[]" title="23" value="23" lay-skin="primary" {if $info && in_array('23',$info.hours)}checked{/if}>
    </div>
  </div>

  <div class="layui-form-item layui-hide">
    <button class="layui-btn" lay-submit lay-filter="LAY-user-role-submit" id="LAY-user-role-submit">提交</button>
  </div>
</div>


<script src="/static/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/static/layuiadmin/modules/regionCheckBox/data/region.json"></script>
<script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index', //主入口模块
    regionCheckBox: 'regionCheckBox/regionCheckBox' // 定义组件模块名
  }).use(['index', 'form','regionCheckBox'], function(){
    var $ = layui.$
            ,admin = layui.admin
            ,layer = layui.layer
            ,form = layui.form;
    var regionCheckBox = layui.regionCheckBox;


    //执行实例
    var regionTest = regionCheckBox.render({
      elem: '#regionTest',
      name: 'region', // 对应input name
      value: '{$info.area}', // 赋初始值，'北京,内蒙古,江西-九江'也可以
      width: '100%', // 默认550px
      border: false, // 默认true
      all:null,
      // 初始化完成时执行
      ready: function(){
        // 做些什么
        $('#area').val(getAllChecked(this.name));
      },
      // 点击复选框时执行
      change: function(result){
        // 做些什么
        $('#area').val(getAllChecked(this.name));
      }
    });

    function getAllChecked(name){
      var all = '';
      $("input:checkbox[name="+name+"]:checked").each(function(){
        all += $(this).val() + ',';
      });
      return all.substring(0, all.length-1);
    }



    /* 自定义验证规则 */
    form.verify({
      uids: function (value) {
        if (value.length > 0) {
          var reg = /^[1-9][0-9]*(,[1-9][0-9]*)*$/;
          if (!reg.test(value)) {
            return '请输入正确的值';
          }
        }
      }
    });

  });
</script>
</body>
</html>
